package com.easyattendance.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;


@Entity
@Table(name="TBL_HOLIDAYS")
@IdClass(HolidaysPK.class)
public class Holidays implements Serializable{

	@Id
	@Column(name="holiday_name",length=32,nullable=false)
	private String holiday_name;
	
	@Column(name="holiday_start_date",nullable=false)
	private Date holiday_start_date;
	
	@Column(name="holiday_end_date")
	private Date holiday_end_date;
	
	@Id
	@GenericGenerator(name="section_id",strategy="foreign")
	@Column(name="section_id", nullable=false,length=10)
	private String section_id;	
	
	@ManyToOne
	@JoinColumn(name="section_id", insertable=false, updatable=false, referencedColumnName="section_id")
	private Section section;

	public Holidays() {
		super();
	}

	public Holidays(String holiday_name, Date holiday_start_date,
			Date holiday_end_date, String section_id, Section section) {
		super();
		this.holiday_name = holiday_name;
		this.holiday_start_date = holiday_start_date;
		this.holiday_end_date = holiday_end_date;
		this.section_id = section_id;
		this.section = section;
	}

	public String getHoliday_name() {
		return holiday_name;
	}

	public void setHoliday_name(String holiday_name) {
		this.holiday_name = holiday_name;
	}

	public Date getHoliday_start_date() {
		return holiday_start_date;
	}

	public void setHoliday_start_date(Date holiday_start_date) {
		this.holiday_start_date = holiday_start_date;
	}

	public Date getHoliday_end_date() {
		return holiday_end_date;
	}

	public void setHoliday_end_date(Date holiday_end_date) {
		this.holiday_end_date = holiday_end_date;
	}
	
	public String getSection_id() {
		return section_id;
	}

	public void setSection_id(String section_id) {
		this.section_id = section_id;
	}

	public Section getSection() {
		return section;
	}

	public void setSection(Section section) {
		this.section = section;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((holiday_end_date == null) ? 0 : holiday_end_date.hashCode());
		result = prime * result
				+ ((holiday_name == null) ? 0 : holiday_name.hashCode());
		result = prime
				* result
				+ ((holiday_start_date == null) ? 0 : holiday_start_date
						.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Holidays other = (Holidays) obj;
		if (holiday_end_date.equals(other.holiday_end_date))
			return true;
		if (holiday_name.equals(other.holiday_name))
			return true;
		if (holiday_start_date.equals(other.holiday_start_date))
			return true;
		return false;
	}
	
	
	
}
